require 'View/UIBase/UIBase'

UIActivityPublicConfirm = UIBase.New(PanelResNames.UIActivityPublicConfirm)

function UIActivityPublicConfirm.Init(func, id, subId)
    UIActivityPublicConfirm.activeId = id;
    UIActivityPublicConfirm.subId = subId;
    UIBase.Init(UIActivityPublicConfirm, func);
end

function UIActivityPublicConfirm:OnCreate()
    self.itemList = self:GetChild("itemList")
    self.tipstitleTips = self:GetChild("Txt_Title")
    self.tipstitleTips.text = getLanguage("CommonPop_Title1")
    self.tipsBuy = self:GetChild("Btn_Confirm")
    self.tipsBuy.title = getLanguage("OptionalPool_Btn_Buy")
    self.tipsCancel = self:GetChild("Btn_Cancel")
    self.tipsCancel.title = getLanguage("Btn_Cancel")

    self:RegisterOnClick(self.tipsCancel,self.OnClose);
    self:RegisterOnClick(self:GetChild("Btn_BGClose"),self.OnClose);
    self:RegisterOnClick(self.tipsBuy,self.OnBuy);
end

-- 显示
function UIActivityPublicConfirm:OnEnable()
    if self.activeId == nil or self.subId == nil then
        self:OnBack();
    else
        self:Refresh();
    end
end

function UIActivityPublicConfirm:Refresh()
    self.severData, self.itemData, self.modelTableData = logicMgr.CostManager.getCostData(self.activeId);
    self:ShowTips(self.subId);
end

function UIActivityPublicConfirm:ShowTips(key)
    local tableData = self.itemData[tostring(key)];
    if tableData == nil then
        return ;
    end
    self.cheekItemId = key;
    self.cheekItemMoney = tableData.f_Price;
    self.cheekItemProductId = tableData.f_ProductId;
    local data = clone(decodeJsonStrToTabel(tableData.f_CommonCommodityReward));
    local itemData = decodeJsonStrToTabel(tableData.f_MajorCommodityReward)[1];
    if tableData.f_Type == 1 then
        table.insert(data, 1, {itemData[1] + 201000});
    else
        table.insert(data, 1, itemData);
    end
    logicMgr.CostManager.RefreshItemList(self.itemList, data);
end

function UIActivityPublicConfirm:OnBuy()
    logicMgr.CostManager.getRewardByIdAndIndex(self.activeId, self.cheekItemId, self.cheekItemProductId, 1, self.cheekItemMoney, self.onBuySuccess, self);
    self:OnClose();
end

function UIActivityPublicConfirm:onBuySuccess(id, index)
end

-- 关闭
function UIActivityPublicConfirm:OnClose()
    self:OnBack();
end

-- 隐藏
function UIActivityPublicConfirm:OnDisable()
end

-- 卸载
function UIActivityPublicConfirm:OnDestroy()
end

return UIActivityPublicConfirm